package vehicleRentSys;

//汽车业务类（初始化车，提供租赁服务）

public class VehicleOperation {
	MotoVehicle[] motos = new MotoVehicle[12];

	// 初始化数据：汽车
	public void init() {
		// 轿车：品牌、车牌号、日租金、型号
		motos[0] = new Car("宝马", "云L34568", 800, "X6");
		motos[1] = new Car("宝马", "云L34569", 600, "550i");
		motos[2] = new Car("别克", "云L34468", 300, "林荫大道");
		motos[3] = new Car("别克", "云L34768", 600, "GL8");

		// 客车：品牌、车牌号、日租金、座位数
		motos[4] = new Bus("金龙", "云A32568", 800, 16);
		motos[5] = new Bus("金龙", "云A33569", 1500, 34);
		motos[6] = new Bus("金杯", "云A34568", 800, 16);
		motos[7] = new Bus("金杯", "云A35568", 1500, 34);

		// 客车：品牌、车牌号、日租金、吨位
		motos[8] = new Truck("一汽解放", "云B32368", 1000, 5);
		motos[9] = new Truck("一汽解放", "云B33469", 2000, 10);
		motos[10] = new Truck("重庆红岩", "云B34668", 1000, 5);
		motos[11] = new Truck("重庆红岩", "云B35768", 2000, 10);
	}

	// 提供租赁服务，根据用户的租赁条件去查找相应车辆，并返回相应车辆
	public MotoVehicle rentVehicle(String brand, String type, int seatCount, int tonnage) {
		MotoVehicle rentMoto = null;
		for (MotoVehicle moto : motos) {
			if (moto instanceof Car) {
				Car car = (Car) moto;
				if (brand.equals(car.getBrand()) && type.equals(car.getType())) {
					rentMoto = car;
					break;
				}
			}
			if (moto instanceof Bus) {
				Bus bus = (Bus) moto;
				if (brand.equals(bus.getBrand()) && seatCount == bus.getSeatCount()) {
					rentMoto = bus;
					break;
				}
			}
			if (moto instanceof Truck) {
				Truck truck = (Truck) moto;
				if (brand.equals(truck.getBrand()) && tonnage == truck.getTonnage()) {
					rentMoto = truck;
					break;
				}
			}
		}
		return rentMoto;
	}
}
